Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize hover cards only based on <dl>, not .hover-card-title #1103

Merged
merged 2 commits into from
Dec 16, 2024

Conversation

matthew-white
Copy link
Member

@matthew-white matthew-white commented Dec 13, 2024

This PR addresses an issue with how hover cards are currently sized. See the discussion that starts at #1097 (review).

What has been done to verify that this works as intended?

I tried it out locally in Chrome and Firefox. I also wrote tests.

These are my go-to scenarios when trying things out locally:

  • Select Swahili as the language. "Latest Submission" is a very long translation in Swahili.
  • Hover over a form. The translation for "Latest Submission" should not be truncated.
  • Hover over a form with a long form version. It should be truncated after the width of the <dd> reaches the width of the <dt>.
  • Hover over a form with a short form version. The <dd> should be less wide than the <dt>.

Why is this the best possible solution? Were any other approaches considered?

The key idea here is to hide the heading and footer of the hover card when determining the ideal width of the body.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

I'll ask the QA team to take a look.

Before submitting this PR, please make sure you have:

  • run npm run test and npm run lint and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code or assets from external sources are properly credited in comments or that everything is internally sourced

// Returning 0 means that the default width should be used.
const computeBodyWidth = () => {
if (props.truncateDt) return 0;
const dd = [...el.value.querySelectorAll('dd')];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I don't need to get all the <dd> elements anymore, just the first.

Comment on lines 82 to 84
const otherChildren = [...el.value.querySelectorAll(':scope > *:not(.hover-card-body)')];
for (const child of otherChildren) child.style.display = 'none';
el.value.style.width = 'auto';
Copy link
Contributor

@sadiqkhoja sadiqkhoja Dec 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we move ref="el" from the root to .hover-card-body then we can avoid this, right?

Never mind, I see why this is necessary

Copy link
Contributor

@sadiqkhoja sadiqkhoja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@matthew-white matthew-white merged commit 566d0c5 into master Dec 16, 2024
1 check passed
@matthew-white matthew-white deleted the fix-hover-card-resize branch December 16, 2024 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants